package com.cw.carwashserve.controller;

import com.cw.carwashserve.domain.Services;
import com.cw.carwashserve.service.ServiceService;
import com.ruoyi.common.core.utils.poi.ExcelUtil;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.domain.AjaxResult;
import com.ruoyi.common.core.web.page.TableDataInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@RequestMapping("/services")
public class ServiceController extends BaseController {
    @Autowired
    private ServiceService serviceService;

    /**
     * 分页查询服务列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Services service){
        startPage();
        List<Services> services = serviceService.selectServiceList(service);
        return getDataTable(services);
    }

    /**
     * 获取服务列表详情
     */
    @GetMapping("/detail/{id}")
    public Services detail(@PathVariable(value = "id") Long id){
        return serviceService.selectServiceById(id);
    }

    /**
     * 新增服务
     */
    @PostMapping("/add")
    public AjaxResult add(@RequestBody Services service){
        return toAjax(serviceService.insertService(service));
    }

    /**
     * 修改服务
     */
    @PutMapping("/update")
    public AjaxResult update(@RequestBody Services service){
        return toAjax(serviceService.updateService(service));
    }

    /**
     * 删除服务
     */
    @DeleteMapping("/deleteById/{id}")
    public int delete(@PathVariable Long id){
        return serviceService.deleteServiceById(id);
    }

    /**
     * 批量删除服务
     */
    @DeleteMapping("/deleteByIds/{ids}")
    public int delete(@PathVariable Long[] ids){
        return serviceService.deleteServiceByIds(ids);
    }

    /**p
     * 导出服务列表
     * @param response
     * @param service
     */
    @PostMapping("/export")
    public void export(HttpServletResponse response, Services service){
        List<Services> services = serviceService.selectServiceList(service);
        ExcelUtil<Services> excelUtil = new ExcelUtil<Services>(Services.class);
        excelUtil.exportExcel(response, services, "服务列表");
    }
}
